package com.autumn.domain.entities.auditing;

import java.util.Date;

import javax.persistence.Column;

import com.autumn.common.api.domain.entities.auditing.IFullGmt;
import com.autumn.mybatis.mapper.annotation.ColumnOrder;

/**
 * 具有完全审计的实体抽象
 * 
 * @author 老码农
 *         <p>
 *         Description
 *         </p>
 * @date 2017-12-31 21:25:04
 * @param <TPrimaryKey>
 *            主键类型
 */
public abstract class AbstractFullGmtEntity<TPrimaryKey> extends AbstractGmtModifiedEntity<TPrimaryKey> implements IFullGmt {

	/**
	 * 
	 */
	private static final long serialVersionUID = 3260509509017805235L;	
	

	@ColumnOrder(10200)
	@Column(name = AuditingConsts.COLUMN_IS_DELETE, nullable = false)
	private boolean isDelete;

	@ColumnOrder(10201)
	@Column(name = AuditingConsts.COLUMN_GMT_DELETE)
	private Date gmtDelete;

	@Override
	public boolean getIsDelete() {
		return this.isDelete;
	}

	@Override
	public void setIsDelete(boolean isDelete) {
		this.isDelete = isDelete;
	}

	@Override
	public Date getGmtDelete() {
		return this.gmtDelete;
	}

	@Override
	public void setGmtDelete(Date gmtDelete) {
		this.gmtDelete = gmtDelete;
	}

	@Override
	public void softDelete() {
		this.setIsDelete(true);
		this.setGmtDelete(new Date());
	}

	/**
	 * 插入审核初始化
	 */
	public void insertAuditingInitialize() {
		this.setIsDelete(false);
		this.setGmtCreate(new Date());
		this.setGmtModified(this.getGmtCreate());
		this.setGmtDelete(null);
	}

	/**
	 * 更新审计
	 */
	public void updateAuditing() {
		this.setGmtCreate(this.getGmtCreate());
		this.setIsDelete(this.getIsDelete());
		this.setGmtDelete(null);
		this.setGmtModified(new Date());
	}
}
